package com.shuzi.MediaShare.view;

import com.shuzi.MediaShare.R;
import com.shuzi.MediaShare.gui.movie.MovieHomeActivity;
import com.shuzi.MediaShare.gui.search.SearchResultActivity;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;

/**
 * 搜索布局
 * 
 * @author lung 上午2:18:33 2013
 */
public class SearchLayout extends RelativeLayout implements OnClickListener
{

	private Context context;

	private EditText editText;

	private Button cleanButton;

	private Button searchButton;

	public SearchLayout(Context context, AttributeSet attrs, int defStyle)
	{
		super(context, attrs, defStyle);

		initLayout(context);
	}

	public SearchLayout(Context context, AttributeSet attrs)
	{
		super(context, attrs);
		initLayout(context);
	}

	public SearchLayout(Context context)
	{
		super(context);
		initLayout(context);
	}

	private void initLayout(Context context2)
	{
		this.context = context2;

		addView(View.inflate(context,
				com.shuzi.MediaShare.R.layout.search_layout, null));

		cleanButton = (Button) findViewById(R.id.clean);
		searchButton = (Button) findViewById(R.id.search_button);
		editText = (EditText) findViewById(R.id.searchEditText);

		cleanButton.setOnClickListener(this);
		searchButton.setOnClickListener(this);

	}

	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.search_button:
			if (editText.getText().toString().equals(""))
			{
				Toast.makeText(context, "搜索内容不能为空", Toast.LENGTH_SHORT).show();
			} else
			{
				Intent intent = new Intent();
				intent.setClass(context, SearchResultActivity.class);
				intent.putExtra("KEY", editText.getText().toString());
				context.startActivity(intent);
				editText.setText("");
			}

			break;

		case R.id.clean:
			editText.setText("");
			break;

		default:
			break;
		}

	}

}
